{% extends 'fwMapBase.html' %}


{% block script %}
    {{ super() }}
    <script>
        $(function () {
            $("#butn").on('click', function () {
                var _pids = document.location.pathname.split('/')[3];
                var inputdic = mapDic();
                {#console.log(inputdic);#}
                inputdic["position_id"] = _pids;
                var formInput = formEachGetDict($("#mapforms input"));
                {#console.log(formInput);#}
                $.ajax({
                    url: '/fwmap/GetAddress',
                    type: "post",
                    contentType: "application/json",
                    data: JSON.stringify(inputdic),
                    success: function (data) {
                        if (data.code == 10000) {
                            swal({
                                title: "添加成功！",
                                text: "2秒后自动返回首页。",
                                timer: 1000,
                                showConfirmButton: false
                            }, function () {
                                setInterval(function () {
                                    {#window.history.back(-1);#}
                                    window.open("/fwmap/" + _pids, "_self")
                                }, 1000)
                            });
                        } else if (data.code == 10001) {
                            var resData = data.data[0];
                            for (res in resData) {
                                $("#" + res).parent().next().children('.error-message').html(resData[res]);
                            }
                        } else{
                            // 循环校验input框中的值是否正确
                            for (attr in formInput) {
                                var attr = $("#" + attr);
                                // 获取errorMessage的标签页
                                var errorMessage = attr.parent().next().children('.error-message');
                                var attrVal = attr.val();
                                if (attrVal.length < 1) {
                                    errorMessage.html('不能为空');
                                } else if (attrVal > 65535 || attrVal < 1) {
                                    errorMessage.html('').html('只能是 1-65535');
                                } else if (isNaN(Number(attrVal))) {
                                    errorMessage.html('').html('只能是数字类型 1-65535');
                                }
                            }
                        }
                    }
                });
            });
        });


    </script>
{% endblock %}

